<style>
</style>
<div id="float-container" style="display: none;position: fixed;top:0;left: 0;width: 100vw;height: 100vh;background: rgba(0,0,0, .2);margin: 0 auto;z-index: 1000">
	<div style="width: 80%;margin: 35% auto 0;padding-bottom: 15px;position: relative">
		<img alt="" style="width: 100%" class="img-responsive" src="https://res.bestyoujia.com/web/ZMYJ/activities/act202101/float_mobile_banner.png">

		<img onclick="window.open('https://tb.53kf.com/code/client/5a94a95735e35494ea43bac6762f40560/1');localStorage.setItem('no-pop-202101', true);" alt="" style="width: 34%;position: absolute;left: 14%;top:75%" class="img-responsive" src="https://res.bestyoujia.com/web/UJGC/activities/act202011/mobile/icon1.png">

		<img onclick="window.location.href='{$Request.root}/activities/act202101.html?utm_source=全站弹窗';localStorage.setItem('no-pop-202101', true);" alt="" style="width: 34%;position: absolute;left: 53%;top:75%" class="img-responsive" src="https://res.bestyoujia.com/web/UJGC/activities/act202011/mobile/icon2.png">

		<div style="display: flex; justify-content: center; align-items: center; width: 100% ">
			<img id="float-close" alt="" style="width: 30px;margin-top: 8px;" class="img-responsive" src="https://res.bestyoujia.com/web/UJGC/activities/act202011/mobile/close.svg">
		</div>

	</div>
</div>

<script>
	let second = 0;

	let endTime = 0;

	let timeID = null;

	$('#float-close').on('click', function () {
		$('#float-container').hide();
		const prevCount = localStorage.getItem("close-count-202101") || 0;
		second = 0;
		endTime = 0;
		if((Number(prevCount) + 1) >= 2) {
			localStorage.setItem("no-pop-202101", true);
			clearInterval(timeID);
		}
		localStorage.setItem("close-count-202101", (Number(prevCount) + 1));
	});

	if(!localStorage.getItem("no-pop-202101")) {
		count();
	}

	var tjArr = localStorage.getItem("tos") ? localStorage.getItem("tos") : '[{}]';
	$.cookie('tjRefer', getReferrer() ,{expires:1,path:'/'});
	window.onbeforeunload = function() {
		if($.cookie('tjRefer') == ''){
			var tjT = eval('(' + localStorage.getItem("tos") + ')');
			if(tjT){
				tjT[tjT.length-1].time += second;
				var tos= JSON.stringify(tjT);
				localStorage.setItem("tos", tos);
			}
		} else {
			var tjArr = localStorage.getItem("tos") ? localStorage.getItem("tos") : '[{}]';
			var dataArr = {
				'url' : location.href,
				'time' : second,
				'refer' : getReferrer(),
				'timeIn' : Date.parse(new Date()),
				'timeOut' : Date.parse(new Date()) + (second * 1000)
			};
			tjArr = eval('(' + tjArr + ')');
			tjArr.push(dataArr);
			tjArr= JSON.stringify(tjArr);
			localStorage.setItem("tos", tjArr);
		}
	};

	function count() {
		timeID = window.setInterval(function () {
			second ++;
			const temp = JSON.parse(localStorage.getItem("tos")) || [];

			const arr = temp.map((item) => {
				return item?.time;
			}).filter(Boolean) || [];


			const totalTime = (arr.length > 0) && arr.reduce(function(prev, next, index, array) {
				return prev + next;
			});

			console.log('===用户浏览时长', totalTime+second);

			endTime = totalTime+second;

			if(endTime >= 40) {
				$('#float-container').show();
				localStorage.removeItem("tos");
				// const prevCount = localStorage.getItem("close-count") || 0;
				//
				// if(prevCount + 1 >= 2) {
				// 	localStorage.setItem("no-pop", true);
				// }
				//
				// localStorage.setItem("close-count", prevCount + 1);
			}

		}, 1000);
	}

	function getReferrer() {
		var referrer = '';
		try {
			referrer = window.top.document.referrer;
		} catch(e) {
			if(window.parent) {
				try {
					referrer = window.parent.document.referrer;
				} catch(e2) {
					referrer = '';
				}
			}
		}
		if(referrer === '') {
			referrer = document.referrer;
		}
		return referrer;
	}
</script>
